package com.gxa.xx.controller;

import com.gxa.xx.DTO.RespInfo;
import com.gxa.xx.dao.LocationDao;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "location", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class LocationController {

    private LocationDao locationDao;

    public LocationController(LocationDao locationDao) {
        this.locationDao = locationDao;
    }

    @GetMapping("/provinces")
    public ResponseEntity<RespInfo<List<Map<String, String>>>> getProvinces() {
        List<Map<String, String>> provinces = locationDao.getProvinces();
        RespInfo<List<Map<String, String>>> respInfo = new RespInfo<>();
        respInfo.setCode("1");
        respInfo.setMsg("所有省份信息");
        respInfo.setObj(provinces);
        respInfo.setType("Array<Object>");
        respInfo.setAddition("");
        return new ResponseEntity<>(respInfo, HttpStatus.OK);
    }

    @GetMapping("/cities/{province}")
    public ResponseEntity<RespInfo<List<Map<String, String>>>> getCities(@PathVariable("province") String province) {
        List<Map<String, String>> provinces = locationDao.getCities(province);
        RespInfo<List<Map<String, String>>> respInfo = new RespInfo<>();
        respInfo.setCode("1");
        respInfo.setMsg("对应" + province + "省份的所有城市信息");
        respInfo.setObj(provinces);
        respInfo.setType("Array<Object>");
        respInfo.setAddition("");
        return new ResponseEntity<>(respInfo, HttpStatus.OK);
    }

    @GetMapping("/blocks/{city}")
    public ResponseEntity<RespInfo<List<Map<String, String>>>> getBlocks(@PathVariable("city") String city) {
        List<Map<String, String>> provinces = locationDao.getBlocks(city);
        RespInfo<List<Map<String, String>>> respInfo = new RespInfo<>();
        respInfo.setCode("1");
        respInfo.setMsg("对应" + city + "城市的所有区级信息");
        respInfo.setObj(provinces);
        respInfo.setType("Array<Object>");
        respInfo.setAddition("");
        return new ResponseEntity<>(respInfo, HttpStatus.OK);
    }
}
